package com.mohunhun.controller;

import com.mohunhun.pojo.Dept;
import com.mohunhun.pojo.Result;
import com.mohunhun.service.IDeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.EmptyStackException;
import java.util.List;


@Slf4j
@RestController
@RequestMapping("/depts")
public class DeptController {

    @Autowired
    private IDeptService deptService;

    /**
     * 获取所用部门信息
     * @return 返回的信息
     */
    @GetMapping
    public Result finAll(){
        List<Dept> deptList = deptService.finAll();
        return  Result.success(deptList);
    }


    /**
     * 根据id删除部门
     * @param id 部门id
     */
    @DeleteMapping
    public Result deleteDeptById(Integer id){
        if (id == null ||id <=0) {
            log.warn("id状态异常，id="+id);
           //返回错误信息
            return Result.error();
        }
        deptService.deleteDeptById(id);
        return Result.success();
    }
}
